<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // 力扣652 「寻找重复子树」：
        // 知己知彼,才能判断是否有和自己相同的
        // 子树的可视 字符串
        function findDuplicateSubtrees(root){
            var list = [];
            var map = [];
            var mapList = [];
            // 后序遍历,得到每个节点对应的子树字符串中
            traverse(root)
            return list
            function traverse(root){
                if(root==null){
                    return '#'
                }
                var left = traverse(root.left)
                var right = traverse(root.right);
                var subTree = left +','+right+','+root.val;
                if(!map.includes(subTree)){
                    map.push(subTree);
                }else{
                    if(!mapList.includes(subTree)){
                        mapList.push(subTree)
                        list.push(root)
                    }    
                }
                return subTree
            }
        }
        
    </script>
</body>
</html>